/*java jdk 1.7+
# -*- coding: utf-8 -
'''
Created on 2020年05月10日
@author: zxyong 13738196011
'''*/

package com.zxy.business;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URLDecoder;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.zxy.cache.Cache_Power_Control;
import com.zxy.cache.Mock_Test;
import com.zxy.common.Com_Fun;
import com.zxy.common.Com_Para;
import com.zxy.common.Db_Common_InterFace;
import com.zxy.common.ParamName_InterFace;
import com.zxy.common.PooledConnection_InterFace;
import com.zxy.db1.Db_Common1;
import com.zxy.db10.Db_Common10;
import com.zxy.db2.Db_Common2;
import com.zxy.db3.Db_Common3;
import com.zxy.db4.Db_Common4;
import com.zxy.db5.Db_Common5;
import com.zxy.db6.Db_Common6;
import com.zxy.db7.Db_Common7;
import com.zxy.db8.Db_Common8;
import com.zxy.db9.Db_Common9;
import com.zxy.main.Init_Page;
import com.zxy.model.Return_Value;
import com.zxy.model.T_DB_CONFIG;
import com.zxy.model.T_PROC_INPARAM;
import com.zxy.model.T_PROC_OUTPARAM;
import com.zxy.model.T_PROC_RETURN;
import com.zxy.pay.Alipay_now;
import com.zxy.pay.WxPayConfig;
import com.zxy.tcp.DelayDataThread;

public class Query_Data
{
	public String		param_dbname	= "";
	public String		session_id		= "";
	public Return_Value	rv				= new Return_Value();
	public int 			pageNumber 		= 0;
	public int 			pageSize		= 0;

	public Query_Data()
	{
	}

	public Query_Data(Return_Value trv)
	{
		rv = trv;
	}

	// 根据接口参数判断接口权限
	private Cache_Power_Control get_Power_Control(String sub_code, String sub_usercode, String param_name, String strIP)
	{
		Cache_Power_Control cpc = new Cache_Power_Control();
		// 接口全局缓存开关
		if(Com_Para.CachePowerControl == 1)
		{
			// 根据sub_code,sub_usercode,param_name,strIP参数判断是否具有对应接口权限
			cpc.run(sub_code,sub_usercode,param_name,strIP);
			// 无对应权限
			if(!cpc.getError().toString().equals(""))
			{
				this.rv.s_result = 0;
				this.rv.err_desc = cpc.getError();
			}
		}else
		{
			// 实时根据sub_code,sub_usercode,param_name,strIP参数判断是否具有对应接口权限
			Power_Control pcl = new Power_Control(sub_code,sub_usercode,param_name,strIP);
			if(!pcl.getError().toString().equals(""))
			{
				this.rv.s_result = 0;
				this.rv.err_desc = pcl.getError();
			}else
			{
				cpc.setError(pcl.getError());
				cpc.setParam_name(param_name);
				cpc.setSub_code(sub_code);
				cpc.setSUB_IP(strIP);
				cpc.setSub_usercode(sub_usercode);
				cpc.setTpn(pcl.getTpn());
				cpc.setTsp(pcl.getTsp());
				cpc.setTss(pcl.getTss());
				cpc.setTsu(pcl.getTsu());
				cpc.setTsup(pcl.getTsup());
			}
		}
		return cpc;
	}

	// 获取数据接口
	public StringBuilder GetDataList(String sub_code, String sub_usercode, String param_name, ArrayList<String> aryParamValue, StringBuilder strUrl, String delay_data, String delay_code, String strIP, Hashtable<String, String> htParam)
	{
		StringBuilder sbd = new StringBuilder();
		Cache_Power_Control cpc = get_Power_Control(sub_code,sub_usercode,param_name,strIP);
		// 接口无权限
		if(!cpc.getError().toString().equals(""))
			return cpc.getError();
		if(!java.util.Objects.equals(this.rv.err_desc.toString(),"成功")
				&& !java.util.Objects.equals(this.rv.err_desc.toString(),""))
			return this.rv.err_desc;
		// 延时获取数据 从文件中读取，需要传递delay_code和delay_data参数
		if(delay_data.equals("1") && delay_code.length() == 32)
		{
			try
			{
				com.zxy.adminlog.UsAdmin_Log uL = new com.zxy.adminlog.UsAdmin_Log(Com_Para.ApplicationPath,sbd,0);
				sbd.delete(0,sbd.length());
				sbd.append(uL.ReadData(delay_code,param_name));
			}
			catch(IOException e)
			{
				this.rv.s_result = 0;
				this.rv.err_desc.delete(0,this.rv.err_desc.length());
				this.rv.err_desc.append(Com_Fun.get_ope_result(param_name,"0","延时获取数据失败:"
						+ e.getMessage()));
				return this.rv.err_desc;
			}
		}
		// 延时请求数据,将数据写入文件中
		else if(delay_data.equals("0") && delay_code.length() == 32)
		{
			DelayDataThread st = new DelayDataThread(cpc,sub_code,param_name,aryParamValue,delay_code,strIP,htParam);
			st.start();
			sbd.delete(0,sbd.length());
			sbd.append(Com_Fun.get_ope_result(param_name,"1","请求延时数据成功,请稍候获取数据"));
		}else
		{
			sbd.delete(0,sbd.length());
			// 实时获取接口数据信息
			sbd = Cal_Data(cpc,sub_code,param_name,aryParamValue,strIP,htParam);
		}
		// 接口集数据，一次性获取2个或2个以上接口数据信息
		if(param_name.equals("APP_USER_ZXY"))
		{
			JSONObject jso = null;
			try
			{
				jso = new JSONObject(sbd.toString());
				JSONArray jsoary = jso.getJSONArray("APP_USER_ZXY");
				String strNextInfName = "";
				for(int i = 0;i < jsoary.length();i++)
				{
					JSONObject temobj = jsoary.getJSONObject(i);
					String strINFNAME = temobj.getString("INF_EN_NAME");
					//子接口参数
					String URL_IN_PARAM = Com_Fun.s_decode(temobj.getString("URL_IN_PARAM"));
					if(!strINFNAME.equals(strNextInfName))
					{
						// 子接口参数
						ArrayList<String> arySubParamValue = new ArrayList<String>();
						if(URL_IN_PARAM.length() > 0)
						{
							int k = 0;
							for(String strtemParam: URL_IN_PARAM.split(","))
							{
								strtemParam = aryParamValue.get(Integer.valueOf(strtemParam.replace("param_value",""))-1);
								arySubParamValue.add(k,strtemParam);
								k++;
							}
						}
						// 子接口权限验证
						cpc = get_Power_Control(sub_code,sub_usercode,strINFNAME,strIP);
						if(!cpc.getError().toString().equals(""))
						{
							return cpc.getError();
						}
						JSONObject jsonSub = new JSONObject(Cal_Data(cpc,sub_code,strINFNAME,arySubParamValue,strIP,htParam).toString());
						jso.put(strINFNAME,jsonSub.getJSONArray(strINFNAME));
						strNextInfName = strINFNAME;
					}
				}
				sbd.delete(0,sbd.length());
				sbd.append(jso.toString());
			}
			catch(Exception e)
			{
				sbd.delete(0,sbd.length());
				sbd.append(Com_Fun.get_ope_result(param_name,"0","读取APP_USER_ZXY接口失败(GetDataList)JSONException"
						+ e.getMessage()));
			}
		}
		return sbd;
	}

	private StringBuilder AliPay1(ArrayList<String> aryParamValue)
	{
		StringBuilder sbd = new StringBuilder();
		// 判断是否支付报宝支付
		Alipay_now an = new Alipay_now();
		an.WIDout_trade_no = aryParamValue.get(2);
		an.WIDsubject = aryParamValue.get(2);
		an.WIDtotal_amount = "0.01";
		sbd.append(an.OrderInfo());
		return sbd;
	}

	private StringBuilder AliPay2(ArrayList<String> aryParamValue)
	{
		StringBuilder sbd = new StringBuilder();
		// 判断是否支付报宝支付
		Alipay_now an = new Alipay_now();
		an.WIDout_trade_no = aryParamValue.get(2);
		an.WIDsubject = aryParamValue.get(2);
		an.WIDtotal_amount = "0.01";
		sbd.append(an.Pay_Now());
		return sbd;
	}

	private StringBuilder rpt_cpt_list()
	{
		StringBuilder sbd = new StringBuilder();
		Ope_DB_Cent odc = new Ope_DB_Cent();
		JSONObject jso = new JSONObject(new LinkedHashMap());
		JSONArray jsary = new JSONArray();
		try
		{
			// 获取文件或文件夹对象
			File[] fileAry = new File(odc.Get_RptTemp_Path()).listFiles();
			for(File file: fileAry)
			{
				// 遍历fileAry数组
				if(file.isFile() && file.getName().endsWith(".cpt"))
				{
					JSONObject temjso = new JSONObject(new LinkedHashMap());
					temjso.put("rpt_cpt_file",file.getName());
					jsary.put(temjso);
				}
			}
			jso.put("rpt_cpt_list",jsary);
			sbd.append(jso.toString());
		}
		catch(Exception es)
		{
			try
			{
				jso.put("rpt_cpt_list",jsary);
			}
			catch(JSONException e)
			{
			}
			sbd.append(jso.toString());
		}
		return sbd;
	}

	private StringBuilder WxPay_Check(ArrayList<String> aryParamValue, String param_name, String strIP)
	{
		StringBuilder sbd = new StringBuilder();
		WxPayConfig wpc = new WxPayConfig();
		wpc.out_trade_no = aryParamValue.get(2);
		wpc.total_fee = "1";
		wpc.spbill_create_ip = strIP;
		wpc.body = wpc.out_trade_no;
		wpc.InitSign();
		try
		{
			String xmlPerpayid = Com_Fun.SendDataServer(wpc.getOrderInfoApp());
			JSONObject jsob = Com_Fun.xmlToJSON(xmlPerpayid);
			if(jsob.getJSONObject("xml").getString("result_code").toString().equals("SUCCESS"))
			{
				wpc.prepayid = jsob.getJSONObject("xml").getString("prepay_id");
				sbd.append(wpc.getJSONOrderInfo());
			}else if(jsob.getJSONObject("xml").getString("result_code").toString().equals("FAIL"))
			{
				sbd.append(jsob.getJSONObject("xml").getString("err_code_des").toString());
			}else
			{
				sbd.append(jsob.getJSONObject("xml").toString());
			}
		}
		catch(JSONException e)
		{
			this.rv.s_result = 0;
			this.rv.err_desc.delete(0,this.rv.err_desc.length());
			this.rv.err_desc.append(Com_Fun.get_ope_result(param_name,"0","微信支付初始化失败(Cal_Data)JSONException1:"
					+ e.getMessage()));
		}
		return sbd;
	}

	// 实时获取接口数据信息
	public StringBuilder Cal_Data(Cache_Power_Control pcl, String sub_code, String param_name, ArrayList<String> aryParamValue, String strIP, Hashtable<String, String> htParam)
	{
		Ope_DB_Cent opd = new Ope_DB_Cent();
		StringBuilder sbd = new StringBuilder();
		try
		{
			// 支付宝支付
			if(param_name.equals(Com_Para.AliPay_Check))
				return AliPay1(aryParamValue);
			else if(param_name.equals("rpt_cpt_list"))
				return rpt_cpt_list();
			// 读取缓存信息
			else if(param_name.equals("init_page"))
			{
				Init_Page.Init_Load();
				sbd.append(Com_Fun.get_ope_result(param_name,"1","读取缓存信息成功"));
				return sbd;
			}else if(param_name.equals(Com_Para.AliPay_Check2))
				return AliPay2(aryParamValue);
			else if(param_name.equals(Com_Para.WxPay_Check))
				return WxPay_Check(aryParamValue,param_name,strIP);
			// 支付宝授权登录
			else if(param_name.equals("Auth4Alipay"))
			{
				Alipay_now an = new Alipay_now();
				sbd.append(an.AuthInfo());
				return sbd;
			}
			List<T_PROC_INPARAM> tpinpas = opd.Get_T_PROC_INPARAM(pcl.getTpn().MAIN_ID);
			List<T_PROC_OUTPARAM> tpoutpas = opd.Get_T_PROC_OUTPARAM(pcl.getTpn().MAIN_ID);
			List<T_PROC_RETURN> tprtns = opd.Get_T_PROC_RETURN(pcl.getTpn().MAIN_ID);
			// MOCK测试数据发送
			if(pcl.getTpn().IS_MOCK == 1)
			{
				Mock_Test mt = new Mock_Test();
				mt.param_name = param_name;
				mt.mock_data_count = pcl.getTpn().MOCK_DATA_COUNT;
				mt.session_id = this.session_id;
				mt.tprtns = tprtns;
				return mt.Get_Mock_Value();
			}
			/*
			 * ProName 存储过程名 Parameters输入参数 ParamTypes参数类型String Int float Date
			 * ParamOutName输出参数名 ParamOutType输出参数类型
			 */
			String[] Parameters = new String[tpinpas.size()];
			String[] ParamTypes = new String[tpinpas.size()];
			String[] ParamOutName = new String[tpoutpas.size()];
			String[] ParamOutType = new String[tpoutpas.size()];
			// 接口输入参数
			if(aryParamValue.size() > 0)
			{
				for(int i = 0;i < Parameters.length;i++)
				{
					T_PROC_INPARAM tpi = (T_PROC_INPARAM) (tpinpas.get(i));
					String strTem = aryParamValue.get(i).toString();
					if(tpi.IS_URLENCODE == 1 && !strTem.equals(""))
					{
						try
						{
							Parameters[i] = Com_Fun.s_decode(strTem,Com_Para.U_CODE);
						}
						catch(Exception ees)
						{
						}
					}else
						Parameters[i] = strTem;
					ParamTypes[i] = tpi.PARAM_TYPE;
				}
			}else if(!java.util.Objects.equals(htParam,null))
			{
				for(int i = 0;i < Parameters.length;i++)
				{
					T_PROC_INPARAM tpi = (T_PROC_INPARAM) (tpinpas.get(i));
					String strTem = "";
					if(!java.util.Objects.equals(htParam.get(tpi.PARAM_EN_NAME),null))
					{
						strTem = (String) htParam.get(tpi.PARAM_EN_NAME);
					}

					if(tpi.IS_URLENCODE == 1 && !strTem.equals(""))
					{
						try
						{
							Parameters[i] = Com_Fun.s_decode(strTem,Com_Para.U_CODE);
						}
						catch(Exception ees)
						{
						}
					}else
						Parameters[i] = strTem;
					ParamTypes[i] = tpi.PARAM_TYPE;
				}
			}
			// 接口入参拦截器,接口输入反射类调用
			if(!pcl.getTpn().REFLECT_IN_CLASS.equals(""))
			{
				try
				{
					Class<?> objC = Class.forName(pcl.getTpn().REFLECT_IN_CLASS);
					ParamName_InterFace pni = (ParamName_InterFace) objC.newInstance();
					for(Field field: pni.getClass().getDeclaredFields())
					{
						field.setAccessible(true);
						if(field.getName().equals("strResult"))
							continue;
						else if(field.getName().equals("user_main_id"))
							continue;
						else if(field.getName().equals("login_id"))
						{
							field.set(pni,htParam.get("login_id"));
							continue;
						}
						else if(field.getName().equals("login_code"))
						{
							field.set(pni,htParam.get("login_code"));
							continue;
						}else if(field.getName().equals("param_name"))
						{
							field.set(pni,param_name);
							continue;
						}else if(field.getName().equals("session_id"))
						{
							field.set(pni,Com_Fun.GetSessionInfo(session_id));
							continue;
						}
						else if(field.getName().equals("pageNumber"))
						{
							field.set(pni,htParam.get("pageNumber"));
							continue;
						}
						else if(field.getName().equals("pageSize"))
						{
							field.set(pni,htParam.get("pageSize"));
							continue;
						}
						else if(field.getName().indexOf("param_value") == 0)
						{
							try
							{
								String strTem = "";
								int iInd = Integer.valueOf(field.getName().replace("param_value",""));
								if(Parameters.length >= iInd)
								{
									strTem = Parameters[iInd - 1];
								}else if(aryParamValue.size() >= iInd)
								{
									strTem = aryParamValue.get(iInd
											- 1).toString();
								}else if(!java.util.Objects.equals(htParam,null))
								{
									T_PROC_INPARAM tpi = (T_PROC_INPARAM) (tpinpas.get(iInd
											- 1));
									if(!java.util.Objects.equals(htParam.get(tpi.PARAM_EN_NAME),null))
										strTem = (String) htParam.get(tpi.PARAM_EN_NAME);
								}
								field.set(pni,strTem);
							}
							catch(Exception e)
							{
							}
						}
					}
					// 调用
					pni.init_start();
					for(Field field: pni.getClass().getDeclaredFields())
					{
						if(field.getName().equals("user_main_id"))
							continue;
						else if(field.getName().equals("login_code"))
							continue;
						else if(field.getName().equals("login_id"))
							continue;
						else if(field.getName().equals("param_name"))
							continue;
						else if(field.getName().equals("session_id"))
							continue;
						else if(field.getName().indexOf("param_value") != -1)
						{
							try
							{
								int iInd = Integer.valueOf(field.getName().replace("param_value",""));
								Object fieldGetName = Com_Fun.getFieldValueByName(field.getName(),pni);
								if(Parameters.length >= iInd)
									Parameters[iInd
											- 1] = fieldGetName.toString();
								else
									break;
							}
							catch(Exception dsd)
							{
							}
						}else if(field.getName().equals("strResult"))
						{
							Object fieldGetName = Com_Fun.getFieldValueByName(field.getName(),pni);
							if(!fieldGetName.toString().equals(""))
							{
								sbd.delete(0,sbd.length());
								sbd.append(fieldGetName.toString());
								return sbd;
							}
						}
					}
				}
				catch(Exception e)
				{
					Com_Fun.debug_in(e,this.toString(),"接口输入反射类属性值设置或获取失败");
				}
			}
			// 接口输出参数
			for(int i = 0;i < ParamOutName.length;i++)
			{
				T_PROC_OUTPARAM tpi = (T_PROC_OUTPARAM) (tpoutpas.get(i));
				ParamOutName[i] = tpi.PARAM_EN_NAME;
				ParamOutType[i] = tpi.PARAM_TYPE;
			}
			// 调用存储过程
			java.sql.ResultSet rs = null;
			StringBuilder sqlException = null;
			PooledConnection_InterFace pi = null;
			Db_Common_InterFace dbc = null;

			try
			{
				// 根据不同数据源获取通用数据库调用方法
				Ope_DB_Cent odc = new Ope_DB_Cent();
				Object dbcobject = odc.Get_Db_Common(pcl.getTpn().DB_ID);
				dbc = (Db_Common_InterFace) (odc.Obj_To_Db_Common(dbcobject));
				dbc.setPageNumber(this.pageNumber);
				dbc.setPageSize(this.pageSize);
				rs = dbc.Common_Sql_Proc(this.param_dbname
						+ pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
				sqlException = dbc.getSqlException();
				pi = (PooledConnection_InterFace) dbc.getConn_a();
				
				JSONObject jso = new JSONObject(new LinkedHashMap());
				JSONArray jsary = new JSONArray();
				// 接口全局缓存 0:不缓存实时读取 1:接口全局缓存
				if(java.util.Objects.equals(Com_Para.CachePowerControl,1))
				{
					jsary = Com_Fun.ResultSetToJSONCom(rs);
					if(!Com_Para.Is_UserLogin.equals("")
							&& Com_Para.Is_UserLogin.indexOf("[" + param_name
									+ "]") != -1)
					{
						// 用户登陆成功
						if(jsary.getJSONObject(0).getString(Com_Fun.getLowUpp("s_result")).equals("1")
							&& jsary.getJSONObject(0).has(Com_Fun.getLowUpp("LOGIN_ID")))
						{
							jsary.getJSONObject(0).put(Com_Fun.getLowUpp("session_id"),session_id);
							if(!java.util.Objects.equals(Com_Fun.GetHashTable(htParam,"login_id"),""))
								Com_Para.htLoginFailure.remove(Com_Fun.GetHashTable(htParam,"login_id"));
							//用户登录日志记录
							odc.Ins_t_login_log(jsary.getJSONObject(0).getString(Com_Fun.getLowUpp("LOGIN_ID")),
									jsary.getJSONObject(0).getString(Com_Fun.getLowUpp("NICK_NAME")),strIP,"用户登录");
							
						}else if(jsary.getJSONObject(0).getString(Com_Fun.getLowUpp("s_result")).equals("0"))
						{
							//登录失败
							jsary.getJSONObject(0).put(Com_Fun.getLowUpp("session_id"),"");
							//login参数登录失败
							if(!java.util.Objects.equals(Com_Fun.GetHashTable(htParam,"login_id"),"")){
								String error = Com_Fun.login_failure(Com_Fun.GetHashTable(htParam,"login_id"),strIP);
								jsary.getJSONObject(0).put(Com_Fun.getLowUpp("error_desc"),Com_Fun.s_decode(error));
							}
						}
					}
				}else
				{
					int iIndex = 0;
					// 返回值整理
					while(!java.util.Objects.equals(rs,null) && rs.next()
							&& iIndex < 6000)
					{
						JSONObject temjso = new JSONObject(new LinkedHashMap());
						if(iIndex == 0 && !Com_Para.Is_UserLogin.equals("")
								&& Com_Para.Is_UserLogin.indexOf("["
										+ param_name + "]") != -1)
						{
							// 用户登陆成功
							if(rs.getString("s_result").equals("1") 
									&& jsary.getJSONObject(0).has(Com_Fun.getLowUpp("LOGIN_ID"))){
								temjso.put(Com_Fun.getLowUpp("session_id"),session_id);
								//用户登录日志记录
								odc.Ins_t_login_log(jsary.getJSONObject(0).getString(Com_Fun.getLowUpp("LOGIN_ID")),
										jsary.getJSONObject(0).getString(Com_Fun.getLowUpp("NICK_NAME")),strIP,"用户登录");
								if(!java.util.Objects.equals(Com_Fun.GetHashTable(htParam,"login_id"),""))
									Com_Para.htLoginFailure.remove(Com_Fun.GetHashTable(htParam,"login_id"));
							}
							else if(rs.getString("s_result").equals("0")){
								//登录失败
								temjso.put(Com_Fun.getLowUpp("session_id"),"");
								//login参数登录失败
								if(!java.util.Objects.equals(Com_Fun.GetHashTable(htParam,"login_id"),"")){
									String error = Com_Fun.login_failure(Com_Fun.GetHashTable(htParam,"login_id"),strIP);
									jsary.getJSONObject(0).put(Com_Fun.getLowUpp("error_desc"),error);
								}
							}
						}
						String logName = Com_Fun.GetImgPath(param_name);
						// 结果返回值
						for(int i = 0;i < tprtns.size();i++)
						{
							T_PROC_RETURN tpi = (T_PROC_RETURN) (tprtns.get(i));
							if(tpi.RETURN_TYPE.toUpperCase().equals("STRING"))
							{
								temjso.put(Com_Fun.getLowUpp(tpi.RETURN_NAME.trim()),Com_Fun.ReplacePath(logName,Com_Fun.NoNull(rs.getString(tpi.RETURN_NAME.trim())),tpi.IS_IMG,tpi.IS_URLENCODE));
							}else if(tpi.RETURN_TYPE.toUpperCase().equals("INT"))
							{
								temjso.put(Com_Fun.getLowUpp(tpi.RETURN_NAME),rs.getInt(tpi.RETURN_NAME));
							}else if(tpi.RETURN_TYPE.toUpperCase().equals("FLOAT"))
							{
								temjso.put(Com_Fun.getLowUpp(tpi.RETURN_NAME),rs.getFloat(tpi.RETURN_NAME));
							}else if(tpi.RETURN_TYPE.toUpperCase().equals("DATE"))
							{
								String strTemDate = "";
								try
								{
									Date dtTem = java.util.Objects.equals(rs.getDate(tpi.RETURN_NAME),null) ? (new SimpleDateFormat("yyyy-MM-dd").parse("1900-1-1")) : (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(rs.getString(tpi.RETURN_NAME).replace("T"," ")));
									strTemDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dtTem);
								}
								catch(Exception ee)
								{
								}
								temjso.put(Com_Fun.getLowUpp(tpi.RETURN_NAME),strTemDate);
							}
						}
						// 结果输出值
						for(int i = 0;i < tpoutpas.size();i++)
						{
							T_PROC_OUTPARAM tpi = (T_PROC_OUTPARAM) (tpoutpas.get(i));
							if(tpi.PARAM_TYPE.toUpperCase().equals("STRING"))
							{
								temjso.put(Com_Fun.getLowUpp(tpi.PARAM_EN_NAME.trim()),Com_Fun.ReplacePath(logName,Com_Fun.NoNull(rs.getString(tpi.PARAM_EN_NAME.trim())),0,0));
							}else if(tpi.PARAM_TYPE.toUpperCase().equals("INT"))
							{
								temjso.put(Com_Fun.getLowUpp(tpi.PARAM_EN_NAME),rs.getInt(tpi.PARAM_EN_NAME));
							}else if(tpi.PARAM_TYPE.toUpperCase().equals("FLOAT"))
							{
								temjso.put(Com_Fun.getLowUpp(tpi.PARAM_EN_NAME),rs.getFloat(tpi.PARAM_EN_NAME));
							}else if(tpi.PARAM_TYPE.toUpperCase().equals("DATE"))
							{
								String strTemDate = "";
								try
								{
									Date dtTem = java.util.Objects.equals(rs.getDate(tpi.PARAM_EN_NAME),null) ? (new SimpleDateFormat("yyyy-MM-dd").parse("1900-1-1")) : (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(rs.getString(tpi.PARAM_EN_NAME).replace("T"," ")));
									strTemDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dtTem);
								}
								catch(Exception ee)
								{
								}
								temjso.put(Com_Fun.getLowUpp(tpi.PARAM_EN_NAME),strTemDate);
							}
						}
						jsary.put(temjso);
						iIndex++;
					}
				}
				// 数据库sql操作异常信息
				if(jsary.length() == 0 && !sqlException.toString().equals(""))
				{
					JSONObject temjso = new JSONObject(new LinkedHashMap());
					temjso.put(Com_Fun.getLowUpp("s_result"),"0");
					if(Com_Para.ShowSqlError == 1)
					{
						temjso.put(Com_Fun.getLowUpp("error_desc"),Com_Fun.s_encode("失败,"
								+ sqlException.toString()));
					}else
					{
						temjso.put(Com_Fun.getLowUpp("error_desc"),Com_Fun.s_encode("失败,数据库操作出错请查看程序错误日志文件"));
					}
					jsary.put(temjso);
				}
				
				jso.put(pcl.getTpn().INF_EN_NAME,jsary);
				//分页语句Count
				jso.put(pcl.getTpn().INF_EN_NAME+"_ROWS",dbc.getRowsCount());
				
				sbd = new StringBuilder();
				sbd.append(jso.toString());
				// 写入用户session相关信息
				if(!session_id.equals(""))
				{
					if(!Com_Para.Is_UserLogin.equals("")
							&& Com_Para.Is_UserLogin.indexOf("[" + param_name
									+ "]") != -1
							&& jso.getJSONArray(param_name).getJSONObject(0).has(Com_Fun.getLowUpp("login_id")))
						Com_Fun.SetSession(session_id,sbd.toString().replace(param_name,"SESSION_INFO"),((JSONObject) (jso.getJSONArray(param_name).get(0))).getString(Com_Fun.getLowUpp("login_id")));
					else
						// 只更新session时间
						Com_Fun.SetSession(session_id,"","");
				}
				// 写入接口操作次数记录
				opd.Ope_Data_Number(pcl.getTsp(),pcl.getTsup(),pcl.getTpn().MAIN_ID);
			}
			catch(Exception e)
			{
				sbd.delete(0,sbd.length());
				sbd.append(Com_Fun.get_ope_result(param_name,"0","执行该接口出错(Cal_Data)SQLException:" + e.getMessage()));
				this.rv.s_result = 0;
				this.rv.err_desc.delete(0,this.rv.err_desc.length());
				this.rv.err_desc.append(Com_Fun.get_ope_result(param_name,"0","执行该接口出错(Cal_Data)SQLException:" + e.getMessage()));
				try
				{
					com.zxy.adminlog.UsAdmin_Log uLs = new com.zxy.adminlog.UsAdmin_Log(Com_Para.ApplicationPath,new StringBuilder("执行接口出错(Cal_Data)\r\n"
							+ "sub_code=" + sub_code + "&param_name="
							+ param_name + " " + e.getMessage()));
					uLs.WriteLog();
				}
				catch(IOException e1)
				{
				}
			}
			finally
			{
				try
				{
					if(!java.util.Objects.equals(rs,null))
					{
						rs.getStatement().close();
						rs.close();
					}
					if(!java.util.Objects.equals(dbc,null)
							&& !pi.isB_nocursor())
					{
						if(!java.util.Objects.equals(pi,null)
								&& !java.util.Objects.equals(pi.getCalls(),null))
							pi.getCalls().close();
					}else if(!java.util.Objects.equals(dbc,null))
					{
						pi.returnConnection();
					}
				}
				catch(SQLException e)
				{
				}
			}
			// 出参拦截器，输出反射类调用
			if(!pcl.getTpn().REFLECT_OUT_CLASS.equals(""))
			{
				try
				{
					Class<?> objC = Class.forName(pcl.getTpn().REFLECT_OUT_CLASS);
					ParamName_InterFace pni = (ParamName_InterFace) objC.newInstance();
					for(Field field: pni.getClass().getDeclaredFields())
					{
						field.setAccessible(true);
						if(field.getName().equals("strResult"))
						{
							field.set(pni,sbd);
							continue;
						}else if(field.getName().equals("session_id"))
						{
							field.set(pni,Com_Fun.GetSessionInfo(session_id));
							continue;
						}else if(field.getName().equals("param_name"))
						{
							field.set(pni,param_name);
							continue;
						}
						else if(field.getName().equals("lastrowid"))
						{
							field.set(pni,dbc.getLastrowid());
							continue;
						}
						else if(field.getName().indexOf("param_value") != -1)
						{
							try
							{
								int iInd = Integer.valueOf(field.getName().replace("param_value",""));
								if(aryParamValue.size() >= iInd)
									field.set(pni,aryParamValue.get(iInd
											- 1).toString());
								else
									break;
							}
							catch(Exception dsd)
							{
							}
						}
					}
					pni.init_start();
					for(Field field: pni.getClass().getDeclaredFields())
					{
						// 获取属性值
						if(field.getName().equals("strResult"))
						{
							Object fieldGetName = Com_Fun.getFieldValueByName(field.getName(),pni);
							return (StringBuilder) fieldGetName;
						}
					}
				}
				catch(Exception ee)
				{
					sbd.delete(0,sbd.length());
					sbd.append(Com_Fun.get_ope_result(param_name,"0",pcl.getTpn().REFLECT_OUT_CLASS + "=>"
							+ ee.getMessage()));
					this.rv.s_result = 0;
					this.rv.err_desc = sbd;
				}
			}
		}
		catch(Exception sft)
		{
			sbd.delete(0,sbd.length());
			sbd.append(Com_Fun.get_ope_result(param_name,"0",param_name+"=>"+sft.getMessage()));
		}
		return sbd;
	}
}